{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设计产品处理国民关注的资讯热点，收集知乎、微博等热门媒体的当天热榜热搜信息。通过百度智能云的图像识别、文字识别收集讯息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 1267458192182116232, 'result_num': 5, 'result': [{'score': 0.728245, 'root': '非自然图像-彩色动漫', 'keyword': '卡通动漫人物'}, {'score': 0.477125, 'root': '商品-绘画', 'keyword': '图画'}, {'score': 0.308556, 'root': '人物-人物特写', 'keyword': '人脸'}, {'score': 0.155593, 'root': '动物-哺乳类', 'keyword': '兔子'}, {'score': 0.002628, 'root': '非自然图像-屏幕截图', 'keyword': '屏幕截图'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用物体和场景识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.06b2f4af2657b726b4bb958a0e8b1cc6.2592000.1588927386.282335-19324884'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 9088615708538670248, 'words_result_num': 6, 'words_result': [{'words': '整整一天了,卖炸弹的小女孩一个炸弹都没有'}, {'words': '卖出去。夜幕降临,又下起雪来,她又冷又饿,'}, {'words': '赤裸的小脚冻得通红。她终于忍受不住寒冷的'}, {'words': '摧残,轻轻的抽出一个炸弹,小心翼翼地点燃了'}, {'words': '它。于是那天晚上,全城的人都见到了她的祖'}, {'words': '母'}]}\n"
     ]
    }
   ],
   "source": [
    "import base64\n",
    "\n",
    "'''\n",
    "通用文字识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('2.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.ab5d08ace74f4300e922bc1e4592dcf3.2592000.1588928342.282335-19325397'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
